/**
 * <p>Copyright (c) 2011 深圳市鹏途信息技术有限公司 </p>
 * <p>				   All right reserved. 		     </p>
 * 
 * <p>项目名称 ： 	东莞交通工程质量监督综合业务系统        </p>
 * <p>创建者   :	Administrator 
 * 
 * <p>描   述  :   DetectAction.java for com.pengtu.web.project.labs    </p>
 * 
 * <p>最后修改 : $: 2011-8-25-下午05:05:38 v 1.0.0	 Administrator   $     </p>
 * 
*/

package com.pengtu.web.project.labs;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.pengtu.dao.Page;
import com.pengtu.dao.QueryFilter;
import com.pengtu.entity.app.Department;
import com.pengtu.entity.app.Organization;
import com.pengtu.entity.project.DrawingsContractInfo;
import com.pengtu.entity.project.labs.Detectcontract;
import com.pengtu.service.app.AccountManager;
import com.pengtu.service.project.ProjectManager;
import com.pengtu.service.project.labs.DetectcontractManager;
import com.pengtu.utils.web.Struts2Utils;
import com.pengtu.web.BaseActionSupport;

/**
 * 
 * DetectAction
 * 
 * 2011-8-25 下午05:05:38
 * 
 * @version 1.0.0
 * 
 */
public class DetectcontractAction extends BaseActionSupport<Detectcontract> {

	/**
	 * serialVersionUID:TODO
	 *
	 * @since 1.0.0
	 */
	
	private static final long serialVersionUID = 1L;
	public String id;
	public Detectcontract detectcontract;
	public String organizationId;
	public String projectId;
	public String deptId;
	public String typeId;
	public String signid; 
	public Page<Detectcontract> page = new Page<Detectcontract>(10);
	public DetectcontractManager detectcontractManager;
	private AccountManager accountManager;
	private ProjectManager projManager;
	private List<DrawingsContractInfo> drawConList;
	private List<String> drawIdList;
	
	public List<String> getDrawIdList() {
		return drawIdList;
	}

	public void setDrawIdList(List<String> drawIdList) {
		this.drawIdList = drawIdList;
	}

	public List<DrawingsContractInfo> getDrawConList() {
		return drawConList;
	}

	@Override
	public Detectcontract getModel() {
		return detectcontract;
	}

	@Override
	public String list() throws Exception {
		QueryFilter queryfilter = QueryFilter.buildFromHttpRequest(Struts2Utils
				.getRequest());

		if (!page.isOrderBySetted()) {
			page.orderBy("createDate");
			page.order(Page.ASC);
		}
		queryfilter.addFilter("projectId", projectId);
		queryfilter.addFilter("signid", signid);
		//Struts2Utils.getRequest().setAttribute("department", accountManager.getDepartment(deptId));
		page = detectcontractManager.findPageDetect(page, queryfilter);
		return SUCCESS;
	}

	@Override
	public String input() throws Exception {
		if (StringUtils.isNotEmpty(signid)){
			Struts2Utils.getRequest().setAttribute("DrawingsContractInfo", projManager.getSign("id", signid).getContractSet());
		}
			return INPUT;
	}

	@Override
	public String save() throws Exception {
		String mark = Struts2Utils.getParameter("mark");
		String orgId = Struts2Utils.getParameter("orgCode");//orgId为单位id
		//判断是否为直属合同段
		if("0".equals(mark)){
			Department dept = new Department();
			//获得单位信息
			if(StringUtils.isNotEmpty(orgId)){
				Organization org = accountManager.getOrganization(orgId);
				//将单位信息复制给部门表 
				if(null!=org){
					System.out.println(org.getId());
					dept.setOrganization(org);
					dept.setDepCode(System.currentTimeMillis() + "");
					dept.setDepName(org.getOrgName());
					dept.setDepAllName(org.getOrgName());
					dept.setBurderMan(org.getPrincipal());
					dept.setRemark(org.getRemark());
				}
			}
			accountManager.saveDepartment(dept);
			detectcontract.setPartid(dept.getId());
		}
		detectcontract.setOrgId(orgId);
		detectcontractManager.saveDetectcontract(detectcontract);
		return "successMessage";
	}

	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		detectcontractManager.deleteDetectcontract(id);
		Struts2Utils.renderText("1");
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			detectcontract = detectcontractManager.getDetectcontract("id",id);
		} else {
			detectcontract = new Detectcontract();
		}				
	}
	
	
	
	public void setId(String id) {
		this.id = id;
	}

	public Detectcontract getDetectcontract() {
		return detectcontract;
	}

	public void setDetectcontract(Detectcontract detectcontract) {
		this.detectcontract = detectcontract;
	}

	@Autowired
	public void setDetectcontractManager(DetectcontractManager detectcontractManager) {
		this.detectcontractManager = detectcontractManager;
	}

	public Page<Detectcontract> getPage() {
		return page;
	}

	public void setPage(Page<Detectcontract> page) {
		this.page = page;
	}

	public String getOrganizationId() {
		return organizationId;
	}

	public void setOrganizationId(String organizationId) {
		this.organizationId = organizationId;
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	public String getTypeId() {
		return typeId;
	}

	public void setTypeId(String typeId) {
		this.typeId = typeId;
	}

	public String getDeptId() {
		return deptId;
	}

	public void setDeptId(String deptId) {
		this.deptId = deptId;
	}
	

	public String getSignid() {
		return signid;
	}

	public void setSignid(String signid) {
		this.signid = signid;
	}
	
	@Autowired
	public void setProjManager(ProjectManager projManager) {
		this.projManager = projManager;
	}

	@Autowired
	public void setAccountManager(AccountManager accountManager) {
		this.accountManager = accountManager;
	}

}
